/*
 * 具体画图
 * 
 * 
 */
package view.jfreechartTest;

import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.IOException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

public class TimeSeriesExample {

	static TimeSeries pop = null;
	
	public TimeSeriesExample() {

	}

	public TimeSeriesExample(String popName) {

		pop = new TimeSeries(popName, Day.class);
//		pop.add(new Day(28, 7, 2010), 1000);
//		pop.add(new Day(25, 9, 2010), 43);
//		pop.add(new Day(15, 10, 2010), 365);
//		pop.add(new Day(10, 10, 2010), 518);
//		pop.add(new Day(13, 10, 2010), 74);
		
	}
	
	public void DrawXYChart(TimeSeriesCollection dataset){
		
		JFreeChart chart = ChartFactory.createTimeSeriesChart("单卡余额变化情况", "日期",
				"余额", dataset, false, true, false);

		// 设置中文字体
		XYPlot plot = chart.getXYPlot();
		ValueAxis domainAxis = plot.getDomainAxis();
		ValueAxis numberaxis = plot.getRangeAxis(); 

		TextTitle t = chart.getTitle();
		t.setFont(new Font("宋体", Font.BOLD, 40));// 标题文字
		chart.setBackgroundPaint(Color.gray);
		domainAxis.setLabelFont(new Font("宋体", Font.BOLD, 20));// x轴标题
		domainAxis.setTickLabelFont(new Font("黑体", Font.BOLD, 10));// x轴坐标上文字
		numberaxis.setLabelFont(new Font("宋体", Font.BOLD, 20));// y轴标题
		numberaxis.setTickLabelFont(new Font("黑体", Font.BOLD, 10));// y轴坐标上文字

//		chart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 5));// 图例文字

		// 绘图
		try {
//			ChartUtilities.saveChartAsJPEG(new File("X://Timechart.jpg"),
//					chart, 500, 300);

			// 弹出窗口显示
			ChartFrame cf = new ChartFrame("TimeChart", chart);
			cf.pack();
			cf.setVisible(true);

		} catch (Exception e) {
			System.err.println("Problem occurred creating chart.");
		}
		
	}

//	public static void main(String[] args) {
//		// Create a time series chart
//		
//		TimeSeriesExample tse = new TimeSeriesExample("Balance Chart");
//		
//		TimeSeriesCollection dataset = new TimeSeriesCollection();
//		
//		dataset.addSeries(pop);
//		
//		tse.DrawXYChart(dataset);
//		
//	}

	public void DrawXYChart(TimeSeriesCollection dataset, String chartName) {
		// TODO Auto-generated method stub
		JFreeChart chart = ChartFactory.createTimeSeriesChart(chartName, "日期",
				"余额", dataset, true, true, false);

		// 设置中文字体
		XYPlot plot = chart.getXYPlot();
		ValueAxis domainAxis = plot.getDomainAxis();
		ValueAxis numberaxis = plot.getRangeAxis(); 
		LegendTitle legend = chart.getLegend();

		TextTitle t = chart.getTitle();
		t.setFont(new Font("宋体", Font.BOLD, 40));// 标题文字
		chart.setBackgroundPaint(Color.gray);
		domainAxis.setLabelFont(new Font("宋体", Font.BOLD, 20));// x轴标题
		domainAxis.setTickLabelFont(new Font("黑体", Font.BOLD, 10));// x轴坐标上文字
		numberaxis.setLabelFont(new Font("宋体", Font.BOLD, 20));// y轴标题
		numberaxis.setTickLabelFont(new Font("黑体", Font.BOLD, 10));// y轴坐标上文字
		legend.setItemFont(new Font("黑体", Font.BOLD, 11));// 图例文字
		
//		chart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 5));// 图例文字

		// 绘图
		try {
			ChartUtilities.saveChartAsJPEG(new File("E://Timechart.jpg"),
					chart, 500, 300);

			// 弹出窗口显示
			ChartFrame cf = new ChartFrame("TimeChart", chart);
			cf.pack();
			cf.setVisible(true);

		} catch (IOException e) {
			System.err.println("Problem occurred creating chart.");
		}
	}
}